<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>质量管理系统ER图 - 横向布局</title>
    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            max-width: 1800px;
            margin: 0 auto;
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            overflow-x: auto;
        }
        .description {
            margin-top: 30px;
            padding: 15px;
            background-color: #f9f9f9;
            border-left: 4px solid #4b89dc;
            border-radius: 4px;
        }
        .description h2 {
            margin-top: 0;
            color: #4b89dc;
        }
        .description ol {
            padding-left: 20px;
        }
        .description li {
            margin-bottom: 8px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>质量管理系统ER图 - 横向布局</h1>
        
        <div class="mermaid">
erDiagram
    PRODUCT ||--o{ BATCH : "生产"
    PRODUCT ||--o{ INSPECTION_TASK : "检验"
    PRODUCT {
        int id PK
        string name
        string code
        string specification
        string version
        date createTime
        string status
    }
    
    BATCH ||--o{ PROCESS_RECORD : "包含"
    BATCH ||--o{ INSPECTION_RECORD : "检验"
    BATCH {
        int id PK
        string batchNo
        int productId FK
        string productName
        int quantity
        date startTime
        date endTime
        string status
    }
    
    PROCESS ||--o{ PROCESS_RECORD : "执行"
    PROCESS {
        int id PK
        string name
        string code
        string description
        int standardTime
        string timeUnit
    }
    
    PROCESS_RECORD ||--o{ INSPECTION_RECORD : "检验"
    PROCESS_RECORD ||--o{ DEFECT_RECORD : "发现"
    PROCESS_RECORD {
        int id PK
        int batchId FK
        int processId FK
        string status
        date startTime
        date endTime
        string operator
        int quantity
    }
    
    INSPECTION_TASK ||--o{ INSPECTION_RECORD : "执行"
    INSPECTION_TASK {
        int id PK
        string name
        string code
        int productId FK
        string inspectionType
        string frequency
        int itemCount
    }
    
    INSPECTION_RECORD ||--o{ DEFECT_RECORD : "记录"
    INSPECTION_RECORD {
        int id PK
        int taskId FK
        int batchId FK
        int processRecordId FK
        string inspector
        date inspectionTime
        string result
        string remarks
    }
    
    DEFECT_RECORD ||--o{ NONCONFORMING : "产生"
    DEFECT_RECORD {
        int id PK
        string code
        string name
        string defectType
        string severity
        int inspectionRecordId FK
        int processRecordId FK
        string location
        date findTime
        string status
    }
    
    NONCONFORMING ||--o{ REPAIR_TASK : "处理"
    NONCONFORMING {
        int id PK
        string code
        int defectRecordId FK
        int batchId FK
        string disposition
        string dispositionReason
        string dispositionBy
        date dispositionTime
    }
    
    REPAIR_TASK {
        int id PK
        string code
        int nonconformingId FK
        string repairMethod
        string repairer
        date repairTime
        string result
        float cost
    }
    
    SPC_ANALYSIS ||--o| PRODUCT : "分析"
    SPC_ANALYSIS ||--o| BATCH : "分析"
    SPC_ANALYSIS {
        int id PK
        int productId FK
        int batchId FK
        string paramName
        float usl
        float lsl
        float target
        float cp
        float cpk
        float sigma
        date analysisTime
    }
    
    CERTIFICATE_TEMPLATE ||--o{ QUALITY_CERTIFICATE : "生成"
    CERTIFICATE_TEMPLATE {
        int id PK
        string name
        string code
        string content
        string format
        string status
    }
    
    QUALITY_CERTIFICATE {
        int id PK
        int templateId FK
        int productId FK
        int batchId FK
        string certificateNo
        date issueDate
        string issuedBy
        string status
    }
        </div>
        
        <div class="description">
            <h2>图表说明</h2>
            <p>这个ER图采用横向布局，展示了质量管理系统中的主要实体及其关系：</p>
            <ol>
                <li><strong>产品(PRODUCT)</strong> - 系统中的基础实体，包含产品信息</li>
                <li><strong>批次(BATCH)</strong> - 产品生产的具体批次</li>
                <li><strong>工序(PROCESS)</strong> - 生产过程中的标准工序</li>
                <li><strong>工序记录(PROCESS_RECORD)</strong> - 批次执行工序的记录</li>
                <li><strong>检验任务(INSPECTION_TASK)</strong> - 定义的检验标准和要求</li>
                <li><strong>检验记录(INSPECTION_RECORD)</strong> - 具体检验执行记录</li>
                <li><strong>缺陷记录(DEFECT_RECORD)</strong> - 检验中发现的缺陷</li>
                <li><strong>不合格品(NONCONFORMING)</strong> - 缺陷导致的不合格品记录</li>
                <li><strong>维修任务(REPAIR_TASK)</strong> - 不合格品的维修处理</li>
                <li><strong>SPC分析(SPC_ANALYSIS)</strong> - 统计过程控制分析</li>
                <li><strong>证书模板(CERTIFICATE_TEMPLATE)</strong> - 质量证书模板</li>
                <li><strong>质量证书(QUALITY_CERTIFICATE)</strong> - 产品/批次的质量证书</li>
            </ol>
            <p>图表使用横向布局，从左到右展示了质量管理的主要流程：产品定义 → 批次生产 → 工序执行 → 质量检验 → 缺陷处理 → 数据分析与证书生成。</p>
        </div>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            er: {
                diagramPadding: 20,
                layoutDirection: 'LR',  // 关键设置：LR表示从左到右的布局
                entityPadding: 15,
                useMaxWidth: false
            },
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true
            }
        });
    </script>
</body>
</html> 